// src/stores/userStore.ts
import { defineStore } from "pinia";
import type { Status } from "@/types/Status";
import type { News } from "@/types/News";
import { HomeAPI } from "@/api/HomeAPI";



type State = {
    NewsList:{
    result: News[];
    status: Status;
  }
  
};

type Getters = {};

type Actions = {
  getNewsList(data:any):Promise<void>
};

export const NewsStore = defineStore<"News", State, Getters, Actions>(
  "News",
  {
    state: () => ({
        NewsList:{
            result:[],
            status:'idle'
      }
    }
     
     ),
     actions:{
        async  getNewsList(data:any){
            //更新请求状态
            this.NewsList.status = "loading"
            try{
                //获取数据
                const response = await HomeAPI.news_list(data);
                //存储数据
                this.NewsList.result = response.data
                //更新状态
                this.NewsList.status = "success"
            }catch(error){
               //更新状态
               this.NewsList.status = "error"    
            }
           
        }
     },

  }
);